<template>
  <a-card :bordered="false">
    <van-search placeholder="请选择条件查询" readonly @click="showSearchPopup" style="margin-top: -10px;width: 100%;padding: 0px;margin-bottom: 10px"/>

    <div>
      <div class="list">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoadList"
        >

          <div
            class="customer-list"
            v-for="(item,i) in dataSource"
            :key="i"
            @click="constructionDetail(item)">
            <div>
              <div class="name">{{item.customerInfo.name || ''}}</div>
              <div class="contact">
                <span>电话：{{ item.customerInfo.phone || '无' }}</span>
                <span style="margin-left: 20px;">地址：{{ item.customerInfo.address || '无'}}</span>
              </div>
              <div class="contact">
                <span>房屋户型：{{ getDictValue('customer_info_house_type',item.customerInfo.houseType) }}</span>
                <span style="margin-left: 20px;">项目状态：{{ getDictValue('project_manage_project_status', item.projectStatus) }}</span>
              </div>
              <div class="contact">
                <span>开工日期：{{ item.startWorkDate || '无' }}</span>
                <span style="margin-left: 20px;">竣工日期：{{ item.completionDate || '无'}}</span>

              </div>
              <div class="contact">
                <span>实际竣工日期：{{ item.realityCompletionDate || '无' }}</span>
                <span style="margin-left: 20px;">项目进度：{{ getDictValue('customer_info_progress',item.projectProgress) || '无'}}</span>
              </div>
              <div class="contact">
                <span>总工期：{{ item.totalTimeLimit || '无' }}</span>
                <span style="margin-left: 20px;margin-right: 20px">剩余工期：{{ item.surplusTimeLimit || '无'}}</span>
                <span>超期天数：
                  <span v-if="item.exceedTimeLimitNum" style="color: red">
                    {{ item.exceedTimeLimitNum || '无'}}
                  </span>
                  <span v-else>
                    无
                  </span>
                </span>
              </div>
            </div>
          </div>
        </van-list>
      </div>

    </div>
    <van-popup v-model="showSearchPopupFlag" position="top" >
      <a-card :bordered="false">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <div>开工时间：
            <a-input @click="startWorkTime.show = true" v-model="startWorkTime.text" readOnly style="text-align: center;"></a-input>
            <van-popup v-model="startWorkTime.show" round position="bottom">
              <van-picker
                show-toolbar
                title="请选择时间"
                :columns="startWorkDateList"
                value-key="itemText"
                @cancel="startWorkTime.show = false"
                @confirm="changeStartWorkTime" />
            </van-popup>
          </div>
          <div style="margin-top: 5px">竣工时间：
            <a-input @click="completionTime.show = true" v-model="completionTime.text" readOnly style="text-align: center;"></a-input>
            <van-popup v-model="completionTime.show" round position="bottom">
              <van-picker
                show-toolbar
                title="请选择时间"
                :columns="completionDateList"
                value-key="itemText"
                @cancel="completionTime.show = false"
                @confirm="changeCompletionTime" />
            </van-popup>
          </div>
          <div style="margin-top: 5px">工程状态：
            <a-input @click="projectStatus.show = true" v-model="projectStatus.text" readOnly style="text-align: center;"></a-input>
            <van-popup v-model="projectStatus.show" round position="bottom">
              <van-picker
                show-toolbar
                title="请选择时间"
                :columns="projectStatusList"
                value-key="itemText"
                @cancel="projectStatus.show = false"
                @confirm="changeProjectStatus" />
            </van-popup>
          </div>
          <a-row :gutter="24" style="margin-bottom: 10px;margin-top: 10px">
            <a-col :span="12">
              <a-button type="primary" style="width: 100%" @click="searchQuery" icon="search">查询</a-button>
            </a-col>
            <a-col :span="12">
              <a-button type="primary" @click="searchReset" icon="reload" style="width: 100%">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </a-card>
    </van-popup>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import {mixinDevice} from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {filterDictTextByCache} from '@comp/dict/JDictSelectUtil'
  import {getAction} from "../../../../api/manage";

  export default {
    name: 'GhProjectManageList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {  },
    data() {
      return {
        projectStatusList: [],
        startWorkDateList: [],
        completionDateList: [],
        model:{},
        description: '项目工程管理表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '姓名',
            align: "center",
            width: 120,
            dataIndex: 'customerInfo.name',
            scopedSlots: { customRender: 'name' },
          },
          {
            title: '项目地址',
            align: "center",
            dataIndex: 'customerInfo.address'
          },
          {
            title: '房屋户型',
            align: "center",
            dataIndex: 'customerInfo.houseType',
            customRender: (text) => {
              //字典值翻译通用方法
              return filterDictTextByCache('customer_info_house_type', text);
            }
          },
          {
            title: '房屋面积',
            align: "center",
            dataIndex: 'customerInfo.houseArea'
          },
          {
            title: '联系方式',
            align: "center",
            dataIndex: 'customerInfo.phone'
          },
          {
            title: '项目状态',
            align: "center",
            dataIndex: 'projectStatus',
            customRender: (text) => {
              //字典值翻译通用方法
              return filterDictTextByCache('project_manage_project_status', text);
            }
          },
          {
            title: '开工日期',
            align: "center",
            width: 200,
            dataIndex: 'startWorkDate'
          },
          {
            title: '竣工日期',
            align: "center",
            width: 200,
            dataIndex: 'completionDate'
          },
          {
            title: '实际竣工日期',
            align: "center",
            dataIndex: 'realityCompletionDate'
          },
          {
            //<a-progress :percent="100" />
            title: '项目进度',
            align: "center",
            width: 200,
            dataIndex: 'projectProgress',
            scopedSlots: {customRender: 'progressSlot'}
          },
          {
            title: '总工期',
            align: "center",
            dataIndex: 'totalTimeLimit'
          },
          {
            title: '剩余工期',
            align: "center",
            dataIndex: 'surplusTimeLimit'
          },
          {
            title: '超期天数',
            align: "center",
            dataIndex: 'exceedTimeLimitNum',
            scopedSlots: {customRender: 'exceedTimeLimitNum'}
          },
        ],
        /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
        queryParam: {},
        /* 数据源 */
        dataSource: [],

        currentProjectStatus: '',     //选中的项目状态
        currentStartWorkDate: '',     //选中的开工日期
        currentCompletionDate: '',    //选中的竣工日期
        url: {
          list: "/ghProjectManage/list",
          delete: "/ghProjectManage/delete",
          deleteBatch: "/ghProjectManage/deleteBatch",
          exportXlsUrl: "/ghProjectManage/exportXls",
          importExcelUrl: "/ghProjectManage/importExcel",
          getItemsByDictCodeUrl: "/ghProjectManage/getItemsByDictCode"
        },
        dictOptions: {},
        selectedRowKeys: [],
        selectedRows: [],
        startWorkTime:{
          show:false,
          text:'全部',
        },
        completionTime:{
          show:false,
          text:'全部',
        },
        projectStatus:{
          show:false,
          text:'全部',
        },
        finished: false,
        loading: false,
        showSearchPopupFlag: false,
      }
    },
    created() {
      //this.loadData();
      this.initSearchConditionData();
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showSearchPopup(){
        this.showSearchPopupFlag = true
      },
      searchQuery(){
        this.loadData(1);
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
      },
      searchReset() {
        this.currentProjectStatus = ""
        this.currentStartWorkDate = ""
        this.currentCompletionDate = ""
        this.startWorkTime.text = "全部"
        this.completionTime.text = "全部"
        this.projectStatus.text = "全部"
        this.queryParam = {}
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
        this.loadData(1);
      },
      initSearchConditionData() {
        getAction(this.url.getItemsByDictCodeUrl).then(res => {
          if (res.success) {
            this.projectStatusList = res.result.projectStatusDictItemList;
            let startWorkDateList = res.result.startWorkDateItemList;
            let completionDateList = res.result.completionDateItemList;
            this.startWorkDateList = startWorkDateList.filter((item) => item.itemValue !== "customizeTime");
            this.completionDateList = completionDateList.filter((item) => item.itemValue !== "customizeTime");
          }
        })
      },
      //下一页
      onLoadList(){
        this.ipagination.current++
        this.loadData(this.ipagination.current)
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
          this.dataSource = [];
          this.finished = false;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        if (this.currentProjectStatus != null && this.currentProjectStatus != '' && this.currentProjectStatus != 0) {
          params.projectStatus = this.currentProjectStatus;
        }

        if (this.currentStartWorkDate != null && this.currentStartWorkDate != '') {
          params.currentStartWorkDate = this.currentStartWorkDate;
        }

        if (this.currentCompletionDate != null && this.currentCompletionDate != '') {
          params.currentCompletionDate = this.currentCompletionDate;
        }
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = [...this.dataSource, ...res.result.records]
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
          if(res.result.records.length<10){
            this.finished = true;
          }
        }).finally(() => {
          this.loading = false
        })
      },
      constructionDetail(record){
        let key = 11;
        this.$router.push({ path: "/infoTab", query: {id: record.customerId, name: record.customerInfo.name, key: "11"}});
        /*this.$refs.infoTab.add();
        this.$refs.infoTab.title = record.customerInfo.name;
        this.$refs.infoTab.showData(record);*/
      },
      onSelectAll(selected, selectedRows, changeRows) {
        if(selected) {
          let rows = [...selectedRows]
          this.selectedRows = this.selectedRows.concat(rows)
        } else {
          changeRows.forEach(item => {
            const delIndex = this.selectedRows.findIndex((val) => {
              return val.id === item.id
            })
            this.selectedRows.splice(delIndex, 1)
          })
        }
      },
      onSelect(record, selected) {
        if(selected) {
          this.selectedRows.push(record);
        } else {
          const delIndex = this.selectedRows.findIndex((val) => {
            return val.id === record.id
          })
          this.selectedRows.splice(delIndex,1)
        }
      },
      onSelectChange(selectedRowKeys) {
        this.selectedRowKeys = selectedRowKeys;
      },
      changeStartWorkTime(e){
        this.startWorkTime.text = e.itemText
        this.startWorkTime.show = false
        const { key, itemValue, itemText } = e
        this.currentStartWorkDate = itemValue
        let obj = {
          key,
          itemValue,
          itemText
        }
        this.loadData(1)
        this.showSearchPopupFlag = false
      },
      changeCompletionTime(e){
        this.completionTime.text = e.itemText
        this.completionTime.show = false
        const { key, itemValue, itemText } = e
        this.currentCompletionDate = itemValue
        let obj = {
          key,
          itemValue,
          itemText
        }
        this.loadData(1)
        this.showSearchPopupFlag = false
      },
      changeProjectStatus(e) {
        this.projectStatus.text = e.itemText
        this.projectStatus.show = false
        const {key, itemValue, itemText} = e
        this.currentProjectStatus = itemValue
        let obj = {
          key,
          itemValue,
          itemText
        }
        this.loadData(1)
        this.showSearchPopupFlag = false
      },
      getDictValue(code,value){
        if (value != null){
          return filterDictTextByCache(code,value)
        }else {
          return "无"
        }
      }
    }
  }
</script>
<style scoped lang="less">
  @import '~@assets/less/common.less';
  .select-pk{
    display:flex;
    align-items:center;
    margin:10px 0;
    &>span{
      font-weight: bold;
    }
    &-text{
      width: calc(100% - 6em);
      height: 30px;
      text-indent: 1em;
      line-height: 28px;
      border: 1px solid #d9d9d9;
      border-radius: 4px;
    }
  }
  .list{
    overflow-y: scroll;
    height:100vh;
    margin-top: 10px;
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .customer-list{
    /*display: flex;*/
    align-items: center;
    border-top: 1px solid #d9d9d9;
    .name{
      font-size: 13px;
      color: #161616;
      line-height: normal;
      margin-top: 5px;
    }
    .contact{
      margin-top: 5px;
      font-size: 12px;
      color: #a39f9f;
      margin-bottom: 5px;
    }
  }
</style>